//
//  VPBaseNavigationViewController.m
//  VideoPlayer
//
//  Created by A on 2021/5/31.
//

#import "BaseNavigationViewController.h"
#import "UIImage+YYAdd.h"

@interface BaseNavigationViewController ()

@end

@implementation BaseNavigationViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    [[UINavigationBar appearance] setBarTintColor:[UIColor whiteColor]];
    [[UINavigationBar appearance] setTintColor:[UIColor blackColor]]; // 按钮颜色
    [UINavigationBar appearance].backItem.title = @"";
    [UINavigationBar appearance].translucent = NO;
    NSDictionary *titleTextAttributes = @{NSForegroundColorAttributeName : [UIColor blackColor] ,NSFontAttributeName : [UIFont boldSystemFontOfSize:18]};
    [[UINavigationBar appearance] setTitleTextAttributes:titleTextAttributes];
    [[UINavigationBar appearance] setShadowImage:[UIImage new]];

 
    UINavigationBar *bar = [UINavigationBar appearance];
    [UINavigationBar appearance].barStyle = UIBarStyleDefault;
    // 修改NarBar背景
    if (@available(iOS 13, *)) {
        // 返回按钮
        [[UIBarButtonItem appearance] setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:0.1], NSForegroundColorAttributeName: [UIColor clearColor]} forState:UIControlStateNormal];
        
    //    [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60)  forBarMetrics:UIBarMetricsDefault];
        UINavigationBarAppearance *appearance = [[UINavigationBarAppearance alloc] init];
        // 背景色
        appearance.backgroundColor = [UIColor whiteColor];
        // 去掉半透明效果
        appearance.backgroundEffect = nil;
        // 标题字体颜色及大小
//        appearance.titleTextAttributes = @{
//            NSForegroundColorAttributeName : [UIColor whiteColor],
//            NSFontAttributeName : [UIFont boldSystemFontOfSize:18],
//        };
//        [appearance setBackgroundImage:[UIImage imageNamed:@"navigationbar_bg"]];
        // 设置导航栏下边界分割线透明
        appearance.shadowImage = [[UIImage alloc] init];
        // 去除导航栏阴影（如果不设置clear，导航栏底下会有一条阴影线）
        appearance.shadowColor = [UIColor clearColor];
        
        //        navBarAppearance.backgroundColor = [WFCUConfigManager globalManager].naviBackgroudColor;

        appearance.titleTextAttributes = titleTextAttributes;

        // standardAppearance：常规状态, 标准外观，iOS15之后不设置的时候，导航栏背景透明
        bar.standardAppearance = appearance;
        // scrollEdgeAppearance：被scrollview向下拉的状态, 滚动时外观，不设置的时候，使用标准外观
        bar.scrollEdgeAppearance = appearance;
    }else{
        [bar setBackgroundImage:[UIImage imageNamed:@"navigationbar_bg"] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
        [bar setShadowImage:[UIImage imageWithColor:[UIColor clearColor] size:CGSizeMake(kScreenWidth, 1)]];
//        [bar setTranslucent:YES];
    }
    
    // 隐藏底部横线
//        [[UINavigationBar appearance]  setBackgroundImage:[[UIImage alloc] init] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
//        [[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];
//    UINavigationBar *navigationBar = [UINavigationBar appearance];
//    [navigationBar setShadowImage:[UIImage new]];
    
      // 这句话是控制导航栏颜色是否透明。
//        [[UINavigationBar appearance] setTranslucent:NO]
    
    __weak typeof (self) weakSelf = self;
    if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        self.interactivePopGestureRecognizer.delegate = (id)weakSelf;
    }
}

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
    if (self.childViewControllers.count == 1) {
        return NO;
    } return YES;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)dealloc {
    
}

- (BOOL)shouldAutorotate {
    return self.topViewController.shouldAutorotate;
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
    return self.topViewController.supportedInterfaceOrientations;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return self.topViewController.preferredInterfaceOrientationForPresentation;
}

- (nullable UIViewController *)childViewControllerForStatusBarStyle {
    return self.topViewController;
}

- (nullable UIViewController *)childViewControllerForStatusBarHidden {
    return self.topViewController;
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
